package com.wuda.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 汉字检查
 * 
 * @author wuda
 * @version JDK1.7
 * 
 */
public class ChineseCheck {

	private static Pattern CHINESE = Pattern.compile("[\u4e00-\u9fa5]+");

	/**
	 * 根据Unicode编码判断中文汉字和符号
	 * 
	 * @param c
	 *            字符
	 * @return 是否中文汉字和字符
	 */
	public static boolean isChinese(char c) {
		Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
		if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
				|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
				|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
				|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B
				|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
				|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS
				|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION) {
			return true;
		}
		return false;
	}

	/**
	 * 判断是否含有中文
	 * 
	 * @param text
	 *            输入文字
	 * @return 是否含有中文
	 */
	public static boolean containsChinese(String text) {
		if (text == null || text.isEmpty()) {
			return false;
		}
		Matcher matcher = CHINESE.matcher(text);
		if (matcher.find()) {
			return true;
		}
		return false;
	}
}
